package sc.tool.sqlgen.branchinfo;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;

import org.springframework.util.CollectionUtils;

public class DiffUnit {

    public enum DiffType {
        NEW, UPDATE
    };

    public enum Filed {
        BANKCODE, CITYID, PROVID, BRANCHNAME
    }

    private BranchInfo dbData;
    private BranchInfo bankData;
    private List<Object[]> diffFileds = new ArrayList<Object[]>();
    private DiffType diffType;

    public void addDiffFiled(Filed filed, String dbValue, String bankValue) {
        diffFileds.add(new Object[] { filed, dbValue, bankValue });
    }

    public BranchInfo getDbData() {
        return dbData;
    }

    public void setDbData(BranchInfo dbData) {
        this.dbData = dbData;
    }

    public BranchInfo getBankData() {
        return bankData;
    }

    public void setBankData(BranchInfo bankData) {
        this.bankData = bankData;
    }

    public String getDiffDesc() {
        String diffDescPattern = "{0}[{1}!={2}];";
        String diffDesc = "";
        if (!CollectionUtils.isEmpty(diffFileds)) {
            diffDesc = "差异：";
            for (Object[] objArray : diffFileds) {
                diffDesc += MessageFormat.format(diffDescPattern, objArray[0], objArray[1], objArray[2]);
            }
        } else if (DiffType.NEW.equals(diffType)) {
            diffDesc = "新增branchId[" + bankData.getBranchId() + "]";
        }
        return diffDesc;
    }

    public DiffType getDiffType() {
        return diffType;
    }

    public void setDiffType(DiffType diffType) {
        this.diffType = diffType;
    }

    public List<Object[]> getDiffFileds() {
        return diffFileds;
    }

    public void setDiffFileds(List<Object[]> diffFileds) {
        this.diffFileds = diffFileds;
    }

}
